package com.kk.xhr.admin.quartz;

import com.kk.xhr.admin.biz.ISignBizService;
import com.kk.xhr.model.dto.UserInfoDTO;
import com.kk.xhr.model.service.IUserService;
import lombok.RequiredArgsConstructor;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;

import java.text.SimpleDateFormat;
import java.util.List;
import java.util.concurrent.CompletableFuture;
import java.util.concurrent.Executor;

/**
 * 考勤任务(1、每日考勤报告，2、每月考勤报告)
 *
 * @author kkmystery
 * @version 1.0 2021/3/30
 * @since 1.0.0
 */
@Component
@RequiredArgsConstructor
public class CheckWorkTask {
    private static final SimpleDateFormat dateFormat = new SimpleDateFormat("HH:mm:ss");
    private final Executor messageExecutor;
    private final ISignBizService signBizService;
    private final IUserService userService;


    /**
     * 周一到周五每天晚上11点触发生成每日考勤报告
     */
    @Scheduled(cron = "0 0 23 ? * MON-FRI")
    public void generateDayOfReport() {
        List<UserInfoDTO> userList = userService.query();
        userList.forEach(user -> {
            CompletableFuture.runAsync(() -> {
                signBizService.generateReportOfDay(user.getId());
            }, messageExecutor);
        });
    }

    /**
     * 每个月第一天早上10点生成月考勤报告
     */
    @Scheduled(cron = "0 0 10 1 * ?")
    public void generateMouthOfReport() {
        List<UserInfoDTO> userList = userService.query();
        userList.forEach(user -> {
            CompletableFuture.runAsync(() -> {
                signBizService.generateReportOfMouth(user.getId());
            }, messageExecutor);
        });
    }

}
